<template>
  <el-card class="box-card" header="用户管理">
    <DataManageTable
      ref="tableRef"
      :tableConfig="tableConfig"
      @getTableData="getTableData"
      @saveRowEvent="saveRowEvent"
    />
  </el-card>
</template>

<script setup>
import { getTableDataAsync, saveOrUpdateAsync } from '@/api/userManage'
import { useDataManage } from '@/hooks'
import tableConfig from './config/table.config'

const tableRef = ref()
const { getTableData, saveRowEvent } = useDataManage({
  getTableDataAsync,
  saveOrUpdateAsync,
  saveParamsCallBack,
  tableRef
})

function saveParamsCallBack(updateRow, row) {
  let params = null
  const { id, identity } = updateRow.length ? updateRow[0] : row
  params = {
    identity
  }
  // 有id表示是老数据，否则是新数据
  if (Object.hasOwn(row, 'id')) params.id = id
  return params
}
</script>

<style scoped lang="scss">
.box-card {
  height: 100%;

  :deep(.el-card__body) {
    height: calc(100% - 58px);
  }
}
</style>
